//app.js
App({
  
  onLaunch: function () {
    // 播放背景音乐
    var backgroundAudioManager = wx.getBackgroundAudioManager();
      // backgroundAudioManager.title = '宠爱'
      // backgroundAudioManager.epname = '宠爱'
      // backgroundAudioManager.singer = '群星'
      // backgroundAudioManager.coverImgUrl = 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg'
      // // 设置了 src 之后会自动播放
      // backgroundAudioManager.src = 'http://cdn.layoom.top/%E5%AE%A0%E7%88%B1.mp3'
    this.globalData.backgroundAudioManager = backgroundAudioManager;


    if (wx.cloud) {
      wx.cloud.init({
        traceUser: true
      })
    }
    wx.getSystemInfo({
      success: e => {
        this.globalData.StatusBar = e.statusBarHeight;
        let capsule = wx.getMenuButtonBoundingClientRect();
        if (capsule) {
          this.globalData.Custom = capsule;
          this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
        } else {
          this.globalData.CustomBar = e.statusBarHeight + 50;
        }
        this.globalData.ScreenHeight = e.screenHeight;
        this.globalData.ScreenWidth = e.screenWidth;
        this.globalData.WindowHeight = e.windowHeight - 55 - this.globalData.CustomBar;
        this.globalData.WindowWidth = e.windowWidth
      }
    })

    // // 获取用户信息
    // wx.getSetting({
    //   success: res => {
    //     if (res.authSetting['scope.userInfo']) {
    //       // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
    //       wx.getUserInfo({
    //         success: res => {
    //           // 可以将 res 发送给后台解码出 unionId
    //           this.globalData.userInfo = res.userInfo

    //           // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
    //           // 所以此处加入 callback 以防止这种情况
    //           if (this.userInfoReadyCallback) {
    //             this.userInfoReadyCallback(res)
    //           }
    //         }
    //       })
    //     }
    //   }
    // })
  },
  onLoad(){
    
  },
  globalData: {
    userInfo: null,
    hasUserInfo: false
  },

  //渐入，渐出实现 
  show: function (that, param, opacity) {
    var animation = wx.createAnimation({
      //持续时间800ms
      duration: 800,
      timingFunction: 'ease',
    });
    //var animation = this.animation
    animation.opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  },

  //滑动渐入渐出
  slideupshow: function (that, param, px, opacity) {
    var animation = wx.createAnimation({
      duration: 600,
      timingFunction: 'ease',
    });
    animation.translateY(px-20).opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
    var _animation = wx.createAnimation({
      duration: 600,
      timingFunction: 'ease',
    });
    setTimeout(()=>{
      _animation.translateY(px+20).step()
      //将param转换为key
      var json = '{"' + param + '":""}'
      json = JSON.parse(json);
      json[param] = _animation.export()
      //设置动画
      that.setData(json)
    }, 600)
    
  },

  //向右滑动渐入渐出
  sliderightshow: function (that, param, px, opacity) {
    var animation = wx.createAnimation({
      duration: 800,
      timingFunction: 'ease',
    });
    animation.translateX(px).opacity(opacity).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  },
  /**
   * 实现旋转动画，每次旋转 120 * n度
   */
  rotateAni: function (that, param, index) {
    //开始旋转
    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'linear'
    })
    // animation.opacity(0).step()
    animation.rotate(120 * (++that.data[index])).step()
    //将param转换为key
    var json = '{"' + param + '":""}'
    json = JSON.parse(json);
    json[param] = animation.export()
    //设置动画
    that.setData(json)
  },
})